/*
 * @Description  : 公告
 * @Author       : zhao
 * @Date         : 2022-07-28 09:42:19
 * @LastEditors  : zhao
 * @LastEditTime : 2023-02-01 16:59:04
 */


import { defineStore } from 'pinia';
import { UserInfosStates } from './interface';
import { ElMessage } from 'element-plus'
import { GetNoticeList, AddNotice, DeleteNotice, UpdateNotice, PublishNotice, RevokeNotice, GetNotice } from '/@/api/publicity.js';



export const usePublicity = defineStore('publicity', {
	state: () => ({
		userInfos: {

		},
	}),
	actions: {


		//根据查询条件获取对应公告信息
		getNoticeList(data: any): Promise<any> {
			return new Promise((resolve, reject) => {
				GetNoticeList(data).then((res: any) => {
					if (res.code === 200) {
						resolve(res)
					} else {
						reject(res)
						ElMessage.error(res.msg || "查询出错")
					}

				})

			})

		},
		//添加公告
		addNotice(data: any): Promise<any> {
			return new Promise((resolve, reject) => {
				AddNotice(data).then((res: any) => {
					if (res.code === 200) {
						resolve(res)
						ElMessage.success(res.msg || "新增成功")
					} else {
						reject(res)
						ElMessage.error(res.msg || "新增出错")
					}

				})

			})

		},
		//删除公告
		deleteNotice(data: any): Promise<any> {
			return new Promise((resolve, reject) => {
				DeleteNotice(data).then((res: any) => {
					if (res.code === 200) {
						resolve(res)
						ElMessage.success(res.msg || "删除成功")
					} else {
						reject(res)
						ElMessage.error(res.msg || "删除出错")
					}

				})

			})

		},
		//修改公告
		updateNotice(data: any): Promise<any> {
			return new Promise((resolve, reject) => {
				UpdateNotice(data).then((res: any) => {
					if (res.code === 200) {
						resolve(res)
						ElMessage.success(res.msg || "修改成功")
					} else {
						reject(res)
						ElMessage.error(res.msg || "修改出错")
					}
				})
			})
		},
		//撤销公告
		RevokeNotice(data: any): Promise<any> {
			return new Promise((resolve, reject) => {
				RevokeNotice(data).then((res: any) => {
					if (res.code === 200) {
						resolve(res)
						ElMessage.success(res.msg || "撤销成功")
					} else {
						reject(res)
						ElMessage.error(res.msg || "撤销失败")
					}
				})
			})
		},
		//发布公告
		PublishNotice(data: any): Promise<any> {
			return new Promise((resolve, reject) => {
				PublishNotice(data).then((res: any) => {
					if (res.code === 200) {
						resolve(res)
						ElMessage.success(res.msg || "发布成功")
					} else {
						reject(res)
						ElMessage.error(res.msg || "发布失败")
					}
				})
			})
		},
		//公告 详情
		GetNotice(data: any): Promise<any> {
			return new Promise((resolve, reject) => {
				GetNotice(data).then((res: any) => {
					if (res.code === 200) {
						resolve(res)

					} else {
						reject(res)
						ElMessage.error(res.msg || "发布失败")
					}
				})
			})
		},


	},
});
